package com.treeroot.treenet.enums;

import com.treeroot.treenet.common.base.BaseEnum;

/**
 * Create By TreeRoot
 * Create Time: 2023/12/18 03:39
 * Class Name: ProtocolTypeMenu
 * Description:
 * 协议枚举
 *
 * @author TreeRoot
 */
public enum ProtocolTypeMenu implements BaseEnum {
    /**
     * websocket
     */
    WEBSOCKET("0", "websocket"),
    /**
     * http
     */
    HTTP("1", "http"),
    /**
     * tcp
     */
    TCP("2", "tcp"),
    /**
     * udp
     */
    UDP("3", "udp"),
    /**
     * kcp
     */
    KCP("4", "kcp");

    private final String key;
    private final String value;

    ProtocolTypeMenu(String key, String value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public String getKey() {
        return key;
    }

    @Override
    public String getValue() {
        return value;
    }

    /**
     * 按键获取值
     *
     * @param key key
     * @return str
     * 2023/11/06
     */
    public static String getValueByKey(String key) {
        for (ProtocolTypeMenu protocolTypeMenu : ProtocolTypeMenu.values()) {
            if (protocolTypeMenu.getKey().equals(key)) {
                return protocolTypeMenu.getValue();
            }
        }
        return null;
    }

    /**
     * 按键获取枚举
     *
     * @param key key
     * @return 枚举
     */
    public static ProtocolTypeMenu getByKey(String key) {
        for (ProtocolTypeMenu protocolTypeMenu : ProtocolTypeMenu.values()) {
            if (protocolTypeMenu.getKey().equals(key)) {
                return protocolTypeMenu;
            }
        }
        return null;
    }

    /**
     * 按值获取枚举
     *
     * @param value value
     * @return 枚举
     */
    public static ProtocolTypeMenu getByValue(String value) {
        for (ProtocolTypeMenu protocolTypeMenu : ProtocolTypeMenu.values()) {
            if (protocolTypeMenu.getValue().equals(value)) {
                return protocolTypeMenu;
            }
        }
        return null;
    }

}
